package com.rrqs.activity.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMapUtils;
import com.amap.api.maps.model.LatLng;
import com.rrqs.activity.OrderDetailNewActivity;
import com.rrqs.activity.common.Common;
import com.zadtek.xmqishi.R;
import com.rrqs.activity.common.Const;
import com.rrqs.activity.data.OrderDeliveryItemData;
import com.rrqs.views.OnChanged;

public class OrderDeliveryItemAdapter extends CommonAdapter<OrderDeliveryItemData>  {

    private String mainid;    //主订单id
    private String sendaddess;
    private OnClickSendFinishListener onClickSendFinishListener;

    public OrderDeliveryItemAdapter(Context context,
                                    List<OrderDeliveryItemData> datas, int layoutId, String mainid, String sendaddess) {
        super(context, datas, layoutId);
        this.mainid = mainid;
        // TODO Auto-generated constructor stub
        this.sendaddess = sendaddess;
    }

    @Override
    public void convert(final ViewHolders holder, final OrderDeliveryItemData t, final int position) {
        ImageView newtask_order_img = holder.getView(R.id.delivery_order_img);
        TextView newtask_goods_name = holder.getView(R.id.delivery_goods_name);
        TextView newtask_goods_address = holder.getView(R.id.delivery_goods_address);
        LinearLayout getlay = holder.getView(R.id.getlay);

        final Button delivery_button = holder.getView(R.id.delivery_button);
        //2,配送中（确认送达），4.已送达，3.已取消，1未取货
        //状态改为 1：配送中，2：未取货，3：取消中，4：已送达，5：已取消
        //7.31状态改为
        ////5=>待抢单
        ////6=>已抢单,取货中
        ////7=>已取货,配送中
        ////8=>已送达
        ////9=>用户已确认
        ////10=>已评价
        ////11=>订单已取消
        if (t.getStatus().equals("7")) {
            delivery_button.setText("确认送达");
            delivery_button.setBackgroundResource(R.drawable.delivery_submit1);
        } else {
            delivery_button.setBackgroundResource(R.drawable.delivery_submit2);
            if (t.getStatus().equals("5")) {
                delivery_button.setText("待抢单");
            } else if (t.getStatus().equals("6")) {
                delivery_button.setText("取货中");
            } else if (t.getStatus().equals("8")) {
                delivery_button.setText("已送达");
            } else if (t.getStatus().equals("9")) {
                delivery_button.setText("已确认");
            } else if (t.getStatus().equals("10")) {
                delivery_button.setText("已评价");
            } else if (t.getStatus().equals("11")) {
                delivery_button.setText("已取消");
            } else if (t.getStatus().equals("12")) {
                delivery_button.setText("待确认");
            } else if (t.getStatus().equals("13")) {
                delivery_button.setText("商家已接单");
            }
        }
        newtask_goods_name.setText(t.getSite_name());
        newtask_goods_address.setText(t.getSite_addr());

        delivery_button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickSendFinishListener!=null){
                    onClickSendFinishListener.onClickSendFinishListener(v,position);
                }
            }
        });

        getlay.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(mContext, OrderDetailNewActivity.class);
                intent.putExtra("mainid", mainid);
                intent.putExtra("status", "ps");
                intent.putExtra("address", sendaddess);
                mContext.startActivity(intent);
            }
        });
    }

//    public void setOnChanged(OnChanged listener) {
//        this.listener = listener;
//    }



    public void setOnClickSendFinishListener(OnClickSendFinishListener onClickSendFinishListener) {
        this.onClickSendFinishListener = onClickSendFinishListener;
    }

    public static interface OnClickSendFinishListener {
        void onClickSendFinishListener(View view, int position);
    }
}
